//
//  UIFactory.m
//  FarmerOrchard
//
//  Created by Ken Zhang on 14-9-17.
//  Copyright (c) 2014年 Ken Zhang. All rights reserved.
//

#import "UIFactory.h"

@implementation UIFactory
+(UIButton*)makeButton:(NSString*)aTitle font:(float)aFont  backColor:(UIColor*)aBackColor  target:(id)aTarget action:(SEL)aMethod
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = aBackColor;
    btn.titleLabel.font = [UIFont systemFontOfSize:aFont];
    [btn setTitle:aTitle forState:UIControlStateNormal];
    [btn addTarget:aTarget action:aMethod forControlEvents:UIControlEventTouchUpInside];
    return  btn;
}

+(UIImageView *)makeImageView:(NSString*)aImageName
{
    UIImageView* imageView = [[UIImageView alloc] init];
    imageView.userInteractionEnabled = YES;
    [imageView setImage:[UIImage imageNamed:aImageName]];
    return imageView;
}
+(UILabel*)makeLabel:(NSString*)aText textColor:(UIColor*)aColor font:(float)aFont backColor:(UIColor*)aBackColor alignment:(NSTextAlignment)aTextAlignment
{
    UILabel *label = [[UILabel alloc]init];
    label.text = aText;
    label.textAlignment = aTextAlignment;
    label.backgroundColor = aBackColor;
    label.textColor = aColor;
    label.font = [UIFont systemFontOfSize:aFont];
    return label;
}

+(UIView*)makeView:(UIColor*)color
{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = color;
    return view;
}

+(UITextField *) makeTextField:(UIColor *)color textHolder:(NSString *)placeHolder keyBoardType:(UIKeyboardType)keyBoard clearBtn:(UITextFieldViewMode)clearBtnMode textFieldDelegate:(id<UITextFieldDelegate>)tDelegate;
{
    UITextField *text = [[UITextField alloc] init];
    text.delegate = tDelegate;
    text.placeholder = placeHolder;
    text.borderStyle = UITextBorderStyleNone;
    text.keyboardType = keyBoard;
    text.clearButtonMode = clearBtnMode;
    text.textColor = color;
    text.textAlignment = NSTextAlignmentCenter;
    text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    text.returnKeyType = UIReturnKeyDone;
    return text;
}

//创建一个textView
+(UITextView *)makeTextView:(UIColor *)color Delegate:(id<UITextViewDelegate>)tDelegate
{
    UITextView *textView = [[UITextView alloc] init];
    textView.delegate = tDelegate;
    textView.textColor = color;
    textView.font = [UIFont systemFontOfSize:17];
    textView.showsHorizontalScrollIndicator = NO;
    textView.showsVerticalScrollIndicator = NO;
    return textView;
}

//使用颜色绘制图片
+(UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}


@end
